package com.candy.actiivemq.jms;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.io.IOException;

/**
 * @author: candy
 * @date: 2020/9/20
 * @description :
 **/
@Slf4j
public class JmsConsumerListener {

    private final static String URL = "tcp://192.168.0.108:61616";



    public static void main(String[] args) throws JMSException, IOException {

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(URL);
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue syncQueue = session.createQueue("syncQueue");

        MessageConsumer consumer = session.createConsumer(syncQueue);

        consumer.setMessageListener(new CandyMessageListener());
        System.in.read();
        consumer.close();

        session.close();

        connection.close();

    }
}
